import React from 'react';

import AppLayout from '@/layout/index.jsx';

import HomeApp from '@/routers/tic-tac-toe/homeApp.jsx';

const routes = [
  {
    index: true,
    element: <div>Hello World</div>,
    label: '介绍',
  },
  {
    path: 'app',
    element: <HomeApp />,
    label: '应用',
  },
];

const forMartRouter = (list, prenturl) => {
  return (list || []).map(item => {
    const param = {
      key: item.index ? prenturl : `${prenturl}/${item.path}`.replace('//', '/'),
      label: item.label,
    };
    if (item.children) {
      return {
        ...param,
        children: forMartRouter(item.children, item.path),
      };
    }
    return param;
  });
};

export const route = () => {
  const routelist = forMartRouter(routes, '/');
  // eslint-disable-next-line no-console
  console.log('routelist', routelist);
  return routelist;
};

export default [
  {
    path: '/',
    element: <AppLayout />,
    label: '首页',
    children: routes,
  },
];
